package com.ewhale.feitengguest.ui.user.mine

import android.graphics.Color
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import androidx.core.content.ContextCompat
import butterknife.BindView
import com.ewhale.feitengguest.R
import com.ewhale.feitengguest.presenter.user.mine.FeelBackPresenter
import com.ewhale.feitengguest.view.user.mine.FeelBackView
import com.simga.library.activity.MBaseActivity
import com.simga.library.widget.BGButton
import kotlinx.android.synthetic.main.activity_feelback.*

class FeelBackActivity : MBaseActivity<FeelBackPresenter?>(), FeelBackView {

    override fun getViewId(): Int {
        return R.layout.activity_feelback
    }

    override fun init(savedInstanceState: Bundle?) {
        setTitle("意见反馈")
    }

    override fun isUseBaseTitleBar(): Boolean {
        return true
    }

    override fun initListener() {
        et_content!!.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
            override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
                if (s.toString().isNotEmpty()) {
                    btn_commit!!.run {
                        setNormalSolid(ContextCompat.getColor(mContext, R.color.main_color))
                        setTextColor(ContextCompat.getColor(mContext, R.color.white))
                        setNormalStroke(1, ContextCompat.getColor(mContext, R.color.main_color))
                        isEnabled = true
                    }
                } else {
                    btn_commit!!.run {
                        setNormalSolid(Color.parseColor("#EEEEEE"))
                        setTextColor(Color.parseColor("#BBBBC2"))
                        setNormalStroke(1, Color.parseColor("#D4D4D4"))
                        isEnabled = false
                    }
                }
            }

            override fun afterTextChanged(s: Editable) {}
        })
        btn_commit!!.setOnClickListener {
            val content = et_content!!.text.toString()
            presenter!!.commitContent(content)
        }
    }

    override fun showProLoading() {
        showLoading()
    }

    override fun dimissProLoading() {
        dismissLoading()
    }

    override fun showErrorMessage(postCode: Int, code: String, message: String) {
        showErrorMsg(code, message)
    }

    override fun commitSuccess() {
        showToast("感谢您的宝贵意见,我们将竭诚为您服务")
        finish()
    }

    companion object {
        @JvmStatic
        fun open(context: MBaseActivity<*>) {
            context.startActivity(null, FeelBackActivity::class.java)
        }
    }
}